/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.h;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.common.i.k;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.nio.CharBuffer;
import org.json.JSONObject;

public class m {
    private static String a = null;

    public static void a(Context paramContext, String paramString) {
        e.a("SDCardCfgMgr", new Object[] { "saveQTLoginAccount Entry account : " + paramString });
        if (!(TextUtils.isEmpty(paramString))) {
            paramString = k.a(paramString);
            e.a("SDCardCfgMgr", new Object[] { "encode: " + paramString });
        }
        int i = 0;
        try {
            String str1 = Environment.getExternalStorageState();
            if (str1.equals("mounted")) {
                String str2 = Environment.getExternalStorageDirectory() + "/" + ".360gamecentersdk";
                File localFile1 = new File(str2);
                if ((!(localFile1.exists())) || (localFile1.isFile()))
                    localFile1.mkdirs();
                str2 = str2 + "/config";
                File localFile2 = new File(str2);
                if (localFile2.exists())
                    localFile2.delete();
                localFile2.createNewFile();
                if (localFile2.exists()) {
                    JSONObject localJSONObject = new JSONObject();
                    localJSONObject.put("p", paramString);
                    FileOutputStream localFileOutputStream = new FileOutputStream(localFile2, false);
                    localFileOutputStream.write(localJSONObject.toString().getBytes());
                    localFileOutputStream.close();
                    i = 1;
                    e.a("SDCardCfgMgr", new Object[] { "save qt account in sdcard ok!" });
                }
            }
        } catch (Exception localException) {
            e.b("SDCardCfgMgr", "", localException);
        }
        if (i != 0)
            return;
        e.a("SDCardCfgMgr", new Object[] { "save qt account in sdcard failed, save at preference!" });
        g.b(paramContext, "qt_login_account", paramString);
    }

    public static String a(Context paramContext) {
        e.a("SDCardCfgMgr", new Object[] { "get QT account entry" });
        if (!(TextUtils.isEmpty(a))) {
            e.a("SDCardCfgMgr", new Object[] { "get qt account from cache: " + a });
            return a;
        }
        String str1 = null;
        FileReader localFileReader = null;
        try {
            String str2 = Environment.getExternalStorageState();
            if (str2.equals("mounted")) {
                String str3 = Environment.getExternalStorageDirectory() + "/" + ".360gamecentersdk" + "/" + "config";
                File localFile = new File(str3);
                if (localFile.exists()) {
                    long l = localFile.length();
                    e.a("SDCardCfgMgr", new Object[] { "file len: " + Long.toString(l) });
                    if (l <= 50L) {
                        localFileReader = new FileReader(localFile);
                        CharBuffer localCharBuffer = CharBuffer.allocate((int) localFile.length());
                        localFileReader.read(localCharBuffer);
                        String str4 = new String(localCharBuffer.array());
                        JSONObject localJSONObject = new JSONObject(str4);
                        str1 = localJSONObject.optString("p", "");
                        e.a("SDCardCfgMgr", new Object[] { "read qt account: " + str1 });
                    }
                    else {
                        e.a("SDCardCfgMgr", new Object[] { "file too long!" });
                    }
                }
                else {
                    e.a("SDCardCfgMgr", new Object[] { "qt account not exist in sdcard" });
                }
            }
        } catch (Exception localException3) {
            e.b("SDCardCfgMgr", "", localException2);
        } finally {
            if (localFileReader != null)
                try {
                    localFileReader.close();
                } catch (Exception localException4) {}
        }
        if (TextUtils.isEmpty(str1)) {
            str1 = g.h(paramContext, "qt_login_account");
            e.a("SDCardCfgMgr", new Object[] { "get from sdcard read preference: " + str1 });
        }
        a = str1;
        return str1;
    }

    public static boolean b(Context paramContext, String paramString) {
        if (TextUtils.isEmpty(paramString))
            return false;
        String str1 = k.a(paramString);
        String str2 = a(paramContext);
        if (TextUtils.isEmpty(str2))
            return false;
        return str1.equalsIgnoreCase(str2);
    }
}